class Solution {
public:
    vector<vector<string>> rst;
    vector<string> temp;
    vector<vector<string>> partition(string s) {
        partitionStep(s, 0);
        return rst;
    }

    void partitionStep(string &s, int start) {
        if(start == s.length()){
            rst.push_back(temp);
            return;
        }

        for(int i = start; i < s.length(); ++i) {
            if(isPalindrome(s, start, i)){
                temp.push_back(s.substr(start, i - start + 1));
                partitionStep(s, i + 1);
                temp.pop_back();
            }
        }
    }

    bool isPalindrome(string &s, int left, int right) {
        while(left < right) {
            if(s[left++] != s[right--]) return false;
        }

        return true;
    }
};